/*
 * HDDClock.c
 *
 * Created: 17.06.2012 13:09:04
 *  Author: Denis
 */ 


#include <avr/io.h>
#include <avr/interrupt.h>

#define cbi(reg,bit)	reg &= ~(_BV(bit))
#define sbi(reg,bit)	reg |= (_BV(bit))

uint16_t degree;

ISR(INT0_vect)
{
	TCNT0 = 0;

	degree = 0;
}

ISR(TIMER0_OVF_vect)
{
	TCNT1 = 0;
	degree++;
	//if(degree==360) PORTB++;
	PORTB++;
	PORTC=0xFF;
}

ISR(TIMER1_COMPA_vect)
{
	cbi(PORTC,0);
}


ISR(TIMER1_COMPB_vect)
{
	cbi(PORTC,1);
}

ISR(TIMER1_CAPT_vect)
{
	cbi(PORTC,2);	
}

int main(void)
{
	DDRB = 0xFF;
	DDRC = 0xFF;
	
	MCUCR = _BV(ISC01)|_BV(ISC00);
	GICR = _BV(INT0);
	
	TCCR0 = _BV(CS00);
	TCCR1B = _BV(CS10);
	
	TIMSK = _BV(TOIE0)|_BV(OCIE1A)|_BV(OCIE1B);
	
	OCR1A = 100;
	OCR1B = 200;
	ICR1 = 150;
	
	sei();
	
    while(1)
    {
        //TODO:: Please write your application code 
    }
}